package com.kunbo.cn.app.controller;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.kunbo.cn.app.entity.SaleCustomerWaybill;
import com.kunbo.cn.app.service.SaleCustomerWaybillService;
import com.kunbo.cn.util.date.SDate;
import com.kunbo.cn.util.retu.BuildBean;
import com.kunbo.cn.util.retu.CommonResult;
import com.kunbo.cn.util.retu.ResultBean;
/**
  *客户app运单
 * @author bjl  
 * @date 2019年3月27日 
 */
@RestController
@RequestMapping("/customerWaybill")
public class SaleCustomerWaybillController {
	@Autowired
	private SaleCustomerWaybillService Service;
	/**
	 * 新增运单
	 * 
	 */
	@PostMapping("/add")
	public CommonResult add(SaleCustomerWaybill waybill) {
		Service.save(waybill);
		return new CommonResult(true,"操作成功",null);
	}
	@GetMapping("/createCode")
	public String createCode(){
		Map<String,Object> map=new HashMap<String,Object>();
		 String prex = "XSYD";
		 String noticeCode= prex+SDate.getSystemDateYMDHMSToString();
		return noticeCode;
	}
	/**
	 * 获取运输单位
	 * @return
	 */
	@PostMapping("/Carrier")
	public ResultBean<List<Map<String,Object>>> Carrier(
			@RequestParam("login_name")String login_name
			){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "succes", "error",Service.Carrier(login_name));
	}
	/**
	 *
	 * (添加运单即运单拆分)修改销售订单余量
	 * 
	 */
	@PostMapping("/updateOrderMargin")
	public int updateOrderMargin(HttpServletRequest request,HttpServletResponse response) throws SQLException{
		String OrderCode = request.getParameter("orderCode"); //订单编号
		String train_number = request.getParameter("transTotal");//运输量
		  return Service.updateOrderMargin(OrderCode,train_number);
	}
	/**
	 * 客户app运单列表
	 * 
	 */
	@GetMapping("/waybillList")
	public ResultBean<List<Map<String,Object>>> waybillList(
			@RequestParam("login_name")String login_name,
			@RequestParam("page")Integer page,
			@RequestParam("pageSize")Integer pageSize
			){
		ResultBean<List<Map<String,Object>>>  result =  new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "success", "error", Service.waybillList(login_name, page,pageSize));
	}
}
